﻿using Coldairarrow.Business.Goods;
using Coldairarrow.Entity.Goods;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Goods
{
    [Route("/Goods/[controller]/[action]")]
    public class BTB_ShippingAddressController : BaseApiController
    {
        #region DI

        public BTB_ShippingAddressController(IBTB_ShippingAddressBusiness bTB_ShippingAddressBus)
        {
            _bTB_ShippingAddressBus = bTB_ShippingAddressBus;
        }

        IBTB_ShippingAddressBusiness _bTB_ShippingAddressBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 查询所有收货地址----分页
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_ShippingAddress>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _bTB_ShippingAddressBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 查询指定收货地址
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BTB_ShippingAddress> GetTheData(IdInputDTO input)
        {
            return await _bTB_ShippingAddressBus.GetTheDataAsync(input.id);
        }


        /// <summary>
        /// 修改默认地址
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SetsDefaultData(IdInputDTO data)
        {
            await _bTB_ShippingAddressBus.SetDefaultAdress(data.id);
        }

        #endregion

        #region 提交
        /// <summary>
        /// 添加或修改收货地址
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_ShippingAddress data)
        {
            if (data.id.IsNullOrEmpty())
            {
                await _bTB_ShippingAddressBus.AddDataAsync(data);
            }
            else
            {
                await _bTB_ShippingAddressBus.UpdateTheDataAsync(data);
            }
        }

        /// <summary>
        /// 删除指定收货地址
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bTB_ShippingAddressBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}